/**
 * 支持组件方法
 * @param name 方法名称
 * @param args 方法参数
 */
import {assert} from "../../utils/assert";
import {Bundle} from "../core/Bundle";
import {supportFunction} from "../../utils/supportFunction";

class Workflow {
    constructor() {
        this._playerflows = {};
    }

    start(flowData, successCallback, failCallback) {

    }

    get PlayerFlows() {
        return this._playerflows;
    }

    static registerFlow(options) {
        if (this instanceof Bundle) {
            assert(options.key === undefined, 'work flow key can not undefined');
            let playerFlows = WorkFlowInstance.getInstance().PlayerFlows;
            if (!supportFunction.hasProp(playerFlows, this.Key)) {
                playerFlows[this.Key] = {};
            }
            playerFlows[this.Key][options.key] = options;
        } else {
            console.error('Please use Bundle objects for workflow calls');
        }

    }

    static startFlow(key, data, success, fail) {
        if (this instanceof Bundle) {
            const flows = WorkFlowInstance.getInstance().PlayerFlows[this.Key];
            if (supportFunction.hasProp(flows, 'key')) {

            } else {
              console.error('Can not find the specified workflow configuration, key=' + key);
            }
        } else {
            console.error('Please use Bundle objects for workflow calls');
        }
    }
}

const WorkFlowInstance = (function () {
    let instance;
    return {
        name: "WorkFlowInstance",
        getInstance: function () {
            if (instance === undefined) {
                instance = new Workflow();
            }
            return instance
        }
    }
})();

function runModuleMethod(name, args) {
    assert(this.currentContext === undefined, "current context is NULL!");
    this.currentContext.runLifecycle(name, args);
}

export {Workflow};